﻿using System.Xml;
using System.Collections;


namespace GetXsdSQL
{
    public class SchemaXmlHelper
    {
        public static Hashtable getXSDfileCommand(string xsdfileName)
        {
            Hashtable ht = new Hashtable();

            XmlDocument xmlDoc = new XmlDocument();
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.IgnoreComments = true;//忽略文档里面的注释
            XmlReader reader = XmlReader.Create(xsdfileName, settings);
            try
            {
                xmlDoc.Load(reader);
                XmlNode root = xmlDoc.GetElementsByTagName("Tables")[0];
                //XmlNodeList AdapterList  = xmlDoc.get("Tables");

                XmlNodeList AdapterList = root.ChildNodes;
                foreach (XmlNode AdapterRoot in AdapterList)
                {
                    //XmlNode TableNameNode = AdapterRoot;
                    //string TableName = AdapterRoot.Attributes["Name"].Value;
                    //string CommandText = AdapterRoot.InnerText;
                    ht.Add(AdapterRoot.Attributes["Name"].Value, AdapterRoot.InnerText);
                }


            }
            finally
            {
                //释放资源
                reader.Close();
            }

            return ht;
        }

    }
}